<?php

$res = http_post('https://developer-product.zijieapi.com/product/api/add', [
    "access_token" => get_access_token(),
    "product_type" => 1,
    "product" => [
        'common_product_params' => [
            'appid' => 'ttdd96ab2b42a07b6d01',
            'industry_type' => 1,
            'anchor_info' => [
                'video_anchor_info' => [
                    'anchor_title' => '小型汽车'    //视频描点
                ],
            ],
            "path_info_lst" => [
                [
                    "path" => "page/index/index",
                    "query" => [
                        "course_id" => "7"
                    ]
                ]
            ],
            "price_info" => [
                "unit" => "节",
                "price" => 100,
                "real_price" => 100
            ],
            "product_detail_lst" => [
                [
                    "rich_text" => [
                        "text" => "<b><i>驾驶证</i></b>"
                    ],
                    "img_uri" => "product/resource/2e5e2f178fb03db1eb9dae48e7d91505"
                ]
            ],
            "product_img_uri" => "tos-cn-i-b2i6zad4el/75c0dac568b9f4d8c69031b1957a8264", //课程图
            "purchase_precaution" => "小程序内购买课程为课程兑换权益，",
            "first_class" => 70000,
            "second_class" => 70500,
            "title" => "自动挡驾驶证报名",
            "product_fulfillment_lst" => [
                [
                    "fulfillment_content" => [
                        "fulfillment_uri" => "product/resource/2e5e2f178fb03db1eb9dae48e7d91505",
                        "name" => "第一节: 科目一"
                    ],
                    "fulfillment_type" => 3
                ]
            ]
        ],
        "course_params" => [
            "teacher_id" => "",
            "institution_id" => "E_7383974744783110194",
            "course_num" => 4,
            "refund_label" => [
                "type" => 1,
                "day_before_use_info" => [
                    "day" => 30
                ],

            ],
            "use_label" => [
                "valid_date" => "2025-12-01"
            ],
            // "start_timestamp" => 1720057786000,
            // "end_timestamp" => 1751593837000
        ]
    ]
]);
echo $res;
exit;
function get_access_token()
{
    $access_token = json_decode(http_post("https://developer.toutiao.com/api/apps/v2/token", [
        "appid" => "ttdd96ab2b42a07b6d01",
        "grant_type" => "client_credential",
        "secret" => "028db66bdff3fa44cad6f2fafa1faa3d6571b3b4"
    ]), true)['data']['access_token'];
    return $access_token;
}
function getAccessToken()
{
    //检测文件是否存在
    $file = 'access_token.txt';
    if (file_exists($file)) {
        //获取文件的最后修改时间
        $mtime = filemtime($file);
        //获取当前时间
        $now = time();
        //判断是否过期
        if (($now - $mtime) < 300) {
            //未过期，直接读取文件内容
            $access_token = file_get_contents($file);
            return $access_token;
        } else {
            $access_token = get_access_token();
            file_put_contents($file, $access_token);
            return $access_token;

        }
    } else {
        $access_token = get_access_token();
        file_put_contents($file, $access_token);
        return $access_token;
    }
}
function http_post($url, $data)
{
    $postdata = json_encode($data);

    // exit;



    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/json',
            'content' => $postdata,
            'timeout' => 15 * 60
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}